package com.leetcode.LC;

public class LC19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode listNode = new ListNode(0);
        ListNode start = listNode, end = listNode;
        listNode.next = head;

        for (int i = 0; i <= n; i++) {
            end = end.next;
        }

        while (end != null) {
            start = start.next;
            end = end.next;
        }

        start.next = start.next.next;

        return listNode.next;
    }

    public static void main(String[] args) {

    }
}
/**
 * Definition for singly-linked list.
 * public class ListNode {
 * int val;
 * ListNode next;
 * ListNode() {}
 * ListNode(int val) { this.val = val; }
 * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
